package com.beikai.springbootdemo.service.impl;

import com.beikai.springbootdemo.dao.AreaMapper;
import com.beikai.springbootdemo.entity.Area;
import com.beikai.springbootdemo.service.AreaService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

/**
 * @ClassName AreaService
 * @Description TODO
 * @Author Admin
 * @Date 2018/11/20 1:03
 * @Version 1.0
 **/
@Service
public class AreaServiceImpl implements AreaService {

    @Autowired
    private AreaMapper areaMapper;

    @Transactional(rollbackFor = Exception.class)
    @Override
    public boolean addArea(Area area) {
        if (area.getAreaName() != null && !"".equals(area.getAreaName()) ){
            area.setCreateTime(new Date());
            area.setLastEditTime(new Date());

            try {
                int insert = areaMapper.insert(area);
                if (insert > 0){
                    return true;
                }else {
                    throw new RuntimeException("插入区域信息失败");
                }
            }catch (Exception e){
                throw new RuntimeException("插入区域信息失败 : " + e.getMessage());
            }
        }else{
            throw new RuntimeException("插入区域信息失败 : ");
        }
    }
}
